<template>
  <div>
    <el-container>
      <el-header style="height: 10vh;background-color: #373d41;" class="header">
        <div style="font-size: 24px;">
          管理平台
        </div>
        <div>
          欢迎：{{ name }}<el-button style="margin-left: 10px;" @click="quit">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="collapse ? '64px' : '210px'" style="background-color: #333744;height: 90vh;">
          <div class="top" @click="collapse = !collapse"><i class="el-icon-s-fold" v-show="!collapse"></i>
            <i class="el-icon-s-unfold" v-show="collapse"></i>
          </div>
          <el-menu :default-active="$route.path.slice(1)" class="el-menu-vertical-demo" background-color="#333744"
            text-color="#fff" active-text-color="#409eff" :unique-opened="unique" :collapse="collapse"
            :collapse-transition="!unique" router>
            <el-submenu v-for="item in sidebar" :key="item.id" :index="item.id + ''">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="obj in item.children" :key="obj.id" :index="obj.path">{{ obj.authName }}
                </el-menu-item>

              </el-menu-item-group>
            </el-submenu>

          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-for="item in $route.meta.name" :key="item">{{ item }}</el-breadcrumb-item>
          </el-breadcrumb>
          <el-card shadow="always" style="height: 80vh;overflow-y: auto;">
            <router-view />
          </el-card>

        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { menus } from '@/http/user'


export default {
  data() {
    return {
      name: localStorage.getItem("houtainame") || '张三',
      unique: true,
      collapse: false,
      sidebar: []
    }
  },

  methods: {
    quit() {
      localStorage.clear()
      this.$router.push('/login')
    }
  },
  created() {
    menus().then(res => {

      this.sidebar = res.data
    })
  }
}
</script>

<style lang="scss" scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
}

.top {
  width: 100%;
  background-color: #4a5064;
  text-align: center;

  >i {
    font-size: 24px;
    color: #fff;
  }
}
</style>